package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.ApartmentFacility;
import com.atguigu.lease.model.entity.RoomFacility;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.app.service.ApartmentFacilityService;
import com.atguigu.lease.web.app.service.RoomFacilityService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.lease.model.entity.FacilityInfo;
import com.atguigu.lease.web.app.service.FacilityInfoService;
import com.atguigu.lease.web.app.mapper.FacilityInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author liubo
 * @description 针对表【facility_info(配套信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class FacilityInfoServiceImpl extends ServiceImpl<FacilityInfoMapper, FacilityInfo>
        implements FacilityInfoService {
    @Autowired
    private RoomFacilityService roomFacilityService;
    @Autowired
    private ApartmentFacilityService apartmentFacilityService;

    @Override
    public List<FacilityInfo> getRoomFacilityInfoListById(Long id) {
        List<RoomFacility> roomFacilityList = roomFacilityService.list(new LambdaQueryWrapper<RoomFacility>().eq(RoomFacility::getRoomId, id));
        if (roomFacilityList != null && !roomFacilityList.isEmpty()) {
            List<Long> facilityIdList = roomFacilityList.stream().map(RoomFacility::getFacilityId).toList();
            return this.list(new LambdaQueryWrapper<FacilityInfo>().in(FacilityInfo::getId, facilityIdList));
        }
        return null;
    }

    @Override
    public List<FacilityInfo> getApartmentFacilityInfoListById(Long id) {
        List<ApartmentFacility> apartmentFacilityList = apartmentFacilityService.list(new LambdaQueryWrapper<ApartmentFacility>().eq(ApartmentFacility::getApartmentId, id));
        if (apartmentFacilityList != null && !apartmentFacilityList.isEmpty()) {
            List<Long> facilityIdList = apartmentFacilityList.stream().map(ApartmentFacility::getFacilityId).toList();
            return this.list(new LambdaQueryWrapper<FacilityInfo>().in(FacilityInfo::getId, facilityIdList));
        }
        return null;
    }
}




